﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;

namespace EmployeesOrders
{
    public partial class IndexPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void EmployeesTimer_OnTick(object sender, EventArgs e)
        {
 
            ASPNETDataClassesDataContext ctx = new ASPNETDataClassesDataContext();

            var employees = from c in ctx.Employees
                    select new{ID=c.EmployeeID,Name= c.FirstName + " " + c.LastName, Address= c.Address, Phone= c.HomePhone,Buttons= c.EmployeeID    };
        

            GridViewEmployees.DataSource = employees;
            GridViewEmployees.DataBind();
        }

        protected void Employees_IndexChanged(object sender, EventArgs e)
        {
            Thread.Sleep(2000);
            ASPNETDataClassesDataContext ctx = new ASPNETDataClassesDataContext();

            var orders = from c in ctx.Orders
                            where c.EmployeeID == int.Parse(GridViewEmployees.SelectedRow.Cells[0].Text)
                    select c;

            GridViewOrders.DataSource = orders;
            GridViewOrders.DataBind();
        }
    }
}